<?php

declare(strict_types=1);

namespace app\model;

use think\Model;

class NotifyTemplate extends Model
{
    protected $name = 'notify_template';

    protected $autoWriteTimestamp = 'datetime';

    protected $type = [
        'channels' => 'array',
    ];

    protected $append = ['status_label'];

    public const STATUS_DISABLED = 0;
    public const STATUS_ENABLED = 1;

    public static function statusMap(): array
    {
        return [
            self::STATUS_DISABLED => '禁用',
            self::STATUS_ENABLED => '启用',
        ];
    }

    public function messages()
    {
        return $this->hasMany(NotifyMessage::class, 'template_id', 'id');
    }

    public function getStatusLabelAttr(): string
    {
        return self::statusMap()[(int) $this->status] ?? '未知';
    }
}
